package com.example.demo.rabbitmq.routing;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 鱼仔
 * @date 2021/7/1 5:20 下午
 */
@Configuration
public class RoutingConfig {
    //创建一个交换机
    @Bean
    public DirectExchange createDirectFanout() {
        return new DirectExchange("test.direct.exchange");
    }
    //创建direct1.test的队列
    @Bean
    public Queue createDirect1Queue() {
        return new Queue("direct1.test");
    }
    //创建direct2.test的队列
    @Bean
    public Queue createDirect2Queue() {
        return new Queue("direct2.test");
    }
    //绑定交换机和队列1
    @Bean
    public Binding directBinding1(DirectExchange directExchange, Queue createDirect1Queue) {
        return BindingBuilder.bind(createDirect1Queue)
                .to(directExchange)
                // 可以是多个路由键值对
                .with("direct1");
    }
    // 绑定交换机和队列2
    @Bean
    public Binding directBinding2(DirectExchange directExchange, Queue createDirect2Queue) {
        return BindingBuilder.bind(createDirect2Queue)
                .to(directExchange)
                .with("direct2");
    }
}
